<?php
require_once 'init.php';
if(!$sessionID){
	header('location:login.php');
}

$action = isset($_GET['action'])?$_GET['action']:'';
if(!in_array($action,array('wedding','studio','cooperation','guest'))){
	header('location:index.php');
}
//if($action=='wedding'){
	$xml = simplexml_load_file($contentDB);
	$children = $xml->children();
	$content = $children[1];
	$pages = $content->children();
	if($action=="wedding"){
		$page = $pages[2];
	}elseif($action == 'studio'){
		$page = $pages[3];
	}elseif($action=='cooperation'){
		$page = $pages[4];
	}elseif($action=='guest'){
		$page = $pages[5];
	}
	$albums = array();
	foreach($page->children() as $album){
		$attrs = $album->attributes();
		$arr = array();
		$arr['id'] = (int)$attrs['id'];
		$arr['src'] = (string)$attrs['coverUrl'];
		$arr['name'] = (string)$attrs['photoName'];
		$albums[] = $arr;
	}
//}
?>
<html>
<head>
	<meta charset="utf-8" />
	<link rel="stylesheet" href="css/default.css" />
</head>
<body>
	<div class="header"></div>
	<div class="middle">
		<div class="left">
			<?php require_once 'left.php';?>		
		</div>
		<div class="right">
			<a href="albumAdd.php?action=<?php echo $action;?>">添加相册</a>
			<table class="imageTable">
				<tr>
					<th>封面</th><th>相册名称</th><th>操作</th>
				</tr>
			<?php foreach($albums as $item):?>
				<tr>
					<td><img src="<?php echo $host.'/'.$item['src'];?>" width="100" height="100" /></td>
					<td><?php echo $item['name'];?></td>
					<td>
						<a href="albumEdit.php?action=<?php echo $action;?>&id=<?php echo $item['id'];?>">编辑</a> | 
						<a href="albumDel.php?action=<?php echo $action;?>&id<?php echo $item['id'];?>">删除</a> | 
						<a href="img.php?action=<?php echo $action;?>&albumID=<?php echo $item['id'];?>">管理图片</a>
					</td>
				</tr>
			<?php endforeach;?>
			</table>
	</div>
	</div>
	<div class="footer">
	</div>
</body>
</html>
